package com.ruoyi.web.controller.front;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.business.domain.BusinessLeave;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;

import com.ruoyi.front.service.IFrontLeaveService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 请假管理Controller
 * 
 * @author ruoyi
 * @date 2025-01-04
 */
@RestController
@RequestMapping("/front/leave")
public class FrontLeaveController extends BaseController
{
    @Autowired
    private IFrontLeaveService businessLeaveService;

    /**
     * 查询请假管理列表
     */
    @PreAuthorize("@ss.hasPermi('front:leave:list')")
    @GetMapping("/list")
    public TableDataInfo list(BusinessLeave businessLeave)
    {
        startPage();
        List<BusinessLeave> list = businessLeaveService.selectBusinessLeaveList(businessLeave);
        return getDataTable(list);
    }

    /**
     * 导出请假管理列表
     */
    @PreAuthorize("@ss.hasPermi('front:leave:export')")
    @Log(title = "请假管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BusinessLeave businessLeave)
    {
        List<BusinessLeave> list = businessLeaveService.selectBusinessLeaveList(businessLeave);
        ExcelUtil<BusinessLeave> util = new ExcelUtil<BusinessLeave>(BusinessLeave.class);
        util.exportExcel(response, list, "请假管理数据");
    }

    /**
     * 获取请假管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('front:leave:query')")
    @GetMapping(value = "/{leaveId}")
    public AjaxResult getInfo(@PathVariable("leaveId") Long leaveId)
    {
        return success(businessLeaveService.selectBusinessLeaveByLeaveId(leaveId));
    }

    /**
     * 新增请假管理
     */
    @PreAuthorize("@ss.hasPermi('front:leave:add')")
    @Log(title = "请假管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BusinessLeave businessLeave)
    {
        return toAjax(businessLeaveService.insertBusinessLeave(businessLeave));
    }

    /**
     * 修改请假管理
     */
    @PreAuthorize("@ss.hasPermi('front:leave:edit')")
    @Log(title = "请假管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BusinessLeave businessLeave)
    {
        return toAjax(businessLeaveService.updateBusinessLeave(businessLeave));
    }

    /**
     * 删除请假管理
     */
    @PreAuthorize("@ss.hasPermi('front:leave:remove')")
    @Log(title = "请假管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{leaveIds}")
    public AjaxResult remove(@PathVariable Long[] leaveIds)
    {
        return toAjax(businessLeaveService.deleteBusinessLeaveByLeaveIds(leaveIds));
    }
}
